/*
 * @lc app=leetcode.cn id=198 lang=swift
 *
 * [198] 打家劫舍
 */

// @lc code=start
class Solution {
    func rob(_ nums: [Int]) -> Int {
        let n = nums.count
        var dp = Array(repeating: 0, count: n+2)
        for i in stride(from: n-1, through: 0, by: -1) {
            dp[i] = max(dp[i+1], nums[i]+dp[i+2])
        }
        return dp[0]
    }
}
// @lc code=end

